package multiThreading;

/**
 * 第二种：通过实现Runnable接口实现多线程
 * Created by lomo.
 *
 */
public class MultiThreadsByRunNable {

    public static void main(String[] args) {
//        Mains ms = new Mains("lomoa");
//        // 第一个线程
//        new Thread(ms).start();
//        // 第二个线程
//        new Thread(ms).start();
        new Thread(new Mains("lomoa")).start();
        new Thread(new Mains("lomoaa")).start();
    }
}

class Mains implements Runnable {
    private static int N = 5;
    private String name;

    Mains(String s) {
        this.name = s;
        System.out.println("constructor is called --" + s);
    }

    @Override
    public void run() {
        for (int i = 0; i < N; i ++) {
            System.out.println("线程" + this.name + ": " + Thread.currentThread().getName() + "运行了..." + i);
        }
    }
}